package utils;

import java.io.FileInputStream;
import java.io.IOException;
import java.sql.*;
import java.util.Properties;

/**
 * @author 后台赖骏
 * @version 1.0
 */
public class JdbcUtils {
    //1.使用properties将连接获取
    /**
     *
     */
    public static Connection getConnection() throws IOException, SQLException {
        Properties properties = new Properties();
        properties.load(new FileInputStream("mysql.properties"));
        String user = properties.getProperty("user");
        String password = properties.getProperty("password");
        String url = properties.getProperty("url");
        return DriverManager.getConnection(url,user,password);
    }


    public static void close (ResultSet r, Connection c, PreparedStatement ps){
        try {
            if (r !=null){
                r.close();
            }
            if (c!=null){
                c.close();
            }
            if (ps!=null){
                ps.close();
            }
        } catch (SQLException throwable) {
            throw new RuntimeException();
        }
    }


}
